// 乘
export const accMul = (arg1, arg2) => {
	let m = 0
	m += deal(arg1)
	m += deal(arg2)
	let r1 = Number(arg1.toString().replace('.', ''))
	let r2 = Number(arg2.toString().replace('.', ''))
	return (r1 * r2) / Math.pow(10, m)
}
// 求小数点后的数据长度
const deal = arg => {
	let t = 0
	try {
		t = arg.toString().split('.')[1].length
	} catch (e) {}
	return t
}
// 除
export const accDiv = (arg1, arg2) => {
	var t1 = deal(arg1)
	var t2 = deal(arg2)
	var r1 = Number(arg1.toString().replace('.', ''))
	var r2 = Number(arg2.toString().replace('.', ''))
	return (r1 / r2) * Math.pow(10, t2 - t1)
}
// 加
export const accAdd = (arg1, arg2) => {
	let r1 = deal(arg1)
	let r2 = deal(arg2)
	let m = Math.pow(10, Math.max(r1, r2))
	return (accMul(arg1, m) + accMul(arg2, m)) / m
}

// 减
export const accReduce = (arg1, arg2) => {
	let r1 = deal(arg1)
	let r2 = deal(arg2)
	let m = Math.pow(10, Math.max(r1, r2))
	return (accMul(arg1, m) - accMul(arg2, m)) / m
}


/**
 * 保留小数点几位数, 自动补零, 四舍五入
 * @param num: 数值
 * @param digit: 小数点后位数
 * @returns string
 */
export const myFixed = (num, digit) => {
	if (Object.is(parseFloat(num), NaN)) {
		return console.error(`传入的值：${num}不是一个数字`);
	}
	num = parseFloat(num);
	return (Math.round((num + Number.EPSILON) * Math.pow(10, digit)) / Math.pow(10, digit)).toFixed(digit);
}